import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import web from "./web"
import course from "./course"

export default new Vuex.Store({
    state: {
        isLogin: false,
        userId: "",
        token:"",
        userInfo: {
            userId: "",
            userName: "",
            userNickName: "",
            iphoneNo: "",
            email: "",
            headPortraitUrl: "",
            status: "",
            createTime: "",
        }
    },
    mutations: {
        setIsLogin(state, isLogin) {
            state.isLogin = isLogin
        },
        setUserId(state, userId) {
            state.userId = userId
        },
        setToken(state, token) {
            state.token = token
        },
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo
        }
    },
    actions: {
        asyncSetIsLogin(store, isLogin) {
            store.commit('setIsLogin', isLogin)
        },
        asyncSetUserId(state, userId) {
            store.commit('setIsLogin', userId)
        },
        asyncSetToken(state, token) {
            store.commit('setToken', token)
        },
        asyncSetUserInfo(state, userInfo) {
            store.commit('setIsLogin', userInfo)
        }
    },
    getters: {
        getIsLogin(state) {
            return state.isLogin
        },
        getUserId(state) {
            return state.userId
        },
        getToken(state) {
            return state.token
        },
        getUserInfo(state) {
            return state.userInfo
        }
    },
    modules: {
        web,course
    }
})
